package com.yong.sbd.biz.mp.controller;

import com.yong.sbd.biz.mp.entity.SysRole;
import com.yong.sbd.biz.mp.service.SysRoleService;
import com.yong.sbd.common.beans.response.R;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 角色控制器
 *
 * @author Kang Yong
 * @date 2025/10/27
 * @since 1.0.0
 */
@RestController
@RequestMapping("/role")
@RequiredArgsConstructor
public class SysRoleController {
    
    private final SysRoleService sysRoleService;
    
    /**
     * 查询所有角色
     *
     * @return {@link R<List<SysRole>>}
     */
    @GetMapping("/list")
    public R<List<SysRole>> list() {
        return R.success(sysRoleService.list());
    }
    
    /**
     * 根据ID查询角色
     *
     * @param id 角色ID
     * @return {@link R<SysRole>}
     */
    @GetMapping("/{id}")
    public R<SysRole> getById(@PathVariable Long id) {
        return R.success(sysRoleService.getById(id));
    }
    
    /**
     * 添加角色
     *
     * @param sysRole 角色信息
     * @return {@link R<Boolean>}
     */
    @PostMapping
    public R<Boolean> save(@RequestBody SysRole sysRole) {
        return R.success(sysRoleService.save(sysRole));
    }
    
    /**
     * 更新角色
     *
     * @param sysRole 角色信息
     * @return {@link R<Boolean>}
     */
    @PutMapping
    public R<Boolean> update(@RequestBody SysRole sysRole) {
        return R.success(sysRoleService.updateById(sysRole));
    }
    
    /**
     * 删除角色
     *
     * @param id 角色ID
     * @return {@link R<Boolean>}
     */
    @DeleteMapping("/{id}")
    public R<Boolean> delete(@PathVariable Long id) {
        return R.success(sysRoleService.removeById(id));
    }
}